package lesson4

import "sync"

// DataQueue数据缓冲区
type DataQueue struct {
	EmptyCon   *sync.Cond    //缓冲区为空时候的状态标识
	FullCon    *sync.Cond    //缓冲区满了时候的状态标识
	WriteLock  sync.Mutex    //写锁
	ReadLock   sync.Mutex    //读锁
	ReadPoint  int           //读指针
	WritePoint int           //写指针
	Cap        int           //缓冲区大小
	Data       []interface{} //缓冲数据
}

// 创建数据缓冲区
func NewDataQueue(cap int) *DataQueue {
	//rl := &sync.Mutex{}
	//wl := &sync.Mutex{}
	l := &sync.Mutex{}
	return &DataQueue{
		Cap:        cap,
		Data:       make([]interface{}, cap),
		ReadPoint:  0,
		WritePoint: 0,
		EmptyCon:   sync.NewCond(l),
		FullCon:    sync.NewCond(l),
	}
}
